Cover TOC Chap Prev Chap Prev Fig Next Fig Next Chap

Chapter 30: Creating Program Scripts

../ch30/30fig05.gif
Figure 30.5

A donut shape built with a donut-maker program script.

30fig05.wrl
Click on the image to view the VRML scene.

#VRML V2.0 utf8
# The VRML 2.0 Sourcebook
# Copyright (c) 1997
# Andrea L. Ames, David R. Nadeau, and John L. Moreland
Group {
    children [
    # Donut, initially empty
        Shape {
            appearance Appearance {
                material Material { }
            }
            geometry DEF Donut Extrusion {
                crossSection [ ]
                spine [ ]
                creaseAngle 1.57
                beginCap FALSE
                endCap   FALSE
            }
        },
    # Donut maker
        DEF DonutMaker Script {
            url "donutmkr.js"
            field    SFFloat crossSectionRadius     1.0
            field    SFFloat spineRadius            2.0
            field    SFInt32 crossSectionResolution 16
            field    SFInt32 spineResolution        16
            eventIn  SFFloat set_crossSectionRadius
            eventIn  SFFloat set_spineRadius
            eventOut MFVec2f crossSection_changed
            eventOut MFVec3f spine_changed
        }
    ]
}
ROUTE DonutMaker.crossSection_changed TO Donut.set_crossSection
ROUTE DonutMaker.spine_changed        TO Donut.set_spine